package main.java;

import java.util.ArrayList;
import java.util.List;

public class LimitProcessor<T> implements DataProcessor<T> {
    private int limit;

    // 构造器：传入限制数量
    public LimitProcessor(int limit) {
        if (limit < 0) {
            throw new IllegalArgumentException("limit cannot be negative");
        }
        this.limit = limit;
    }

    @Override
    public DataContainer<T> process(DataContainer<T> input) {
        if (input == null) {
            throw new IllegalArgumentException("input cannot be null");
        }
        DataContainer<T> result = new DataContainer<>();
        // 遍历前min(limit, input.size())个元素
        int actualSize = Math.min(limit, input.size());
        for (int i = 0; i < actualSize; i++) {
            result.add(input.get(i));
        }
        return result;
    }

    // 个性化要求：处理器名称包含学生姓名（李蓉曼）
    @Override
    public String getProcessorName() {
        return "李蓉曼的数量限制处理器";
    }
}